package servlet;

import java.io.IOException;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import action.common.StockPlanAction;
import dateChange.DateChage;
import model.common.StockPlan;
public class EditStockPlan extends HttpServlet {
	private static final long serialVersionUID = 1L;

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);

	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");
        response.setContentType("text/html; charset=utf-8");
        
        StockPlanAction act=new StockPlanAction();
        StockPlan sp=new StockPlan();
        
        sp.setGoodsName(request.getParameter("goodsName"));
        sp.setGoodsUnitPrice(Double.parseDouble( request.getParameter("goodsUnitPrice")));
        sp.setGoodsPrice(Double.parseDouble( request.getParameter("goodsPrice")));
        sp.setGoodsSum(Double.parseDouble( request.getParameter("goodsSum")));
        sp.setPaymentDate(DateChage.StringToDate(request.getParameter("paymentDate")));
        sp.setPurcharseDate(DateChage.StringToDate(request.getParameter("purcharseDate")));
        sp.setDeliveryDate(DateChage.StringToDate(request.getParameter("deliveryDate")));
        sp.setGoodsProductionDate(DateChage.StringToDate(request.getParameter("goodsProductionDate")));
        sp.setGoodsStockId(Integer.parseInt(request.getParameter("id")));
        try {
			act.edit(sp);
			System.out.println("a");
			response.sendRedirect("stockplan.jsp");
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

}
